<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="内容菜单" prop="cmsMenuId">
									<el-input v-model="form.cmsMenuId" placeholder="请输入内容菜单" clearable></el-input>
								</el-form-item>
								<el-form-item label="公司" prop="departmentId">
									<el-input v-model="form.departmentId" placeholder="请输入公司" clearable></el-input>
								</el-form-item>
								<el-form-item label="分类" prop="cmsTypeId">
									<el-input v-model="form.cmsTypeId" placeholder="请输入分类" clearable></el-input>
								</el-form-item>
								<el-form-item label="1可点击跳转 2栏目点击展开,不跳转" prop="isHref">
									<el-input v-model="form.isHref" placeholder="请输入1可点击跳转 2栏目点击展开,不跳转" clearable></el-input>
								</el-form-item>
								<el-form-item label="类型 1顶部  2右侧 3底部 4左侧" prop="type">
									<el-input v-model="form.type" placeholder="请输入类型 1顶部  2右侧 3底部 4左侧" clearable></el-input>
								</el-form-item>
								<el-form-item label="样式 1全部展开 2弹出展开  3不展开" prop="style">
									<el-input v-model="form.style" placeholder="请输入样式 1全部展开 2弹出展开  3不展开" clearable></el-input>
								</el-form-item>
								<el-form-item label="自定义链接" prop="url">
									<el-input v-model="form.url" placeholder="请输入自定义链接" clearable></el-input>
								</el-form-item>
								<el-form-item label="自定义页面模板" prop="model">
									<el-input v-model="form.model" placeholder="请输入自定义页面模板" clearable></el-input>
								</el-form-item>
								<el-form-item label="菜单名称" prop="menuName">
									<el-input v-model="form.menuName" placeholder="请输入菜单名称" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import contentAPI from '@/api/content/cmsMenu';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					cmsMenuId: "",
					departmentId: "",
					cmsTypeId: "",
					isHref: "",
					type: "",
					style: "",
					url: "",
					model: "",
					menuName: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await contentAPI.cmsMenu.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.cmsMenuId = data.cmsMenuId;
				this.form.departmentId = data.departmentId;
				this.form.cmsTypeId = data.cmsTypeId;
				this.form.isHref = data.isHref;
				this.form.type = data.type;
				this.form.style = data.style;
				this.form.url = data.url;
				this.form.model = data.model;
				this.form.menuName = data.menuName;
			}
		}
	}
</script>
<style>
</style>
